<?php

include_once 'user.class.php';
include_once 'userMapper.class.php';
define('SALT', '$5$jediphpavanzadoisournewsalt$');

if (isset($_GET['update'])){
    updateUser();
}
else if (isset($_POST['Register'])) {
    registerUser();
}

header( 'Location: index.php' ) ;

function updateUser() {
    $password = crypt($_POST['newPassword'], SALT);
    $mapper = new UserMapper();
    $user = $mapper->findByUsername($_GET['update']);
    $user->set_password($password);
    $mapper->update($user);
}

function registerUser(){
    $password = crypt($_POST['password'], SALT);
    $user = new User(null, $_POST['name'], $password, $_POST['email']);
    $mapper = new UserMapper();
    $id = $mapper->insert($user);
    $user->set_userid($id);
}

function show_register() {
    $_POST["content"] = 1;
}

?>
